package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.service.HistoryService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @auther wangchenghao
 * @date 2020/7/31
 **/
@Controller
@ResponseBody
@RequestMapping("history")
public class HistoryController {
    @Autowired
    HistoryService historyService;

    @ApiOperation("新增历史帖子")
    @RequestMapping(value = "/addPost", method = {RequestMethod.PUT})
    public BaseModel addpost(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                             @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        historyService.addnewhistorypost(user_id,source_id,model);
        return model;
    }

    @ApiOperation("分页查询历史帖子")
    @RequestMapping(value = "/getPost", method = {RequestMethod.GET})
    public BaseModel getpost(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                             @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
       historyService.gethistorypost(user_id,pageQueryModel,model);
        return model;
    }

    @ApiOperation("新增历史景点")
    @RequestMapping(value = "/addPlace", method = {RequestMethod.PUT})
    public BaseModel addplace(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                              @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        historyService.addnewhistoryplace(user_id,source_id,model);
        return model;
    }

    @ApiOperation("分页查询历史景点")
    @RequestMapping(value = "/getPlace", method = {RequestMethod.GET})
    public BaseModel getplace(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                              @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        historyService.gethistoryplace(user_id,pageQueryModel,model);
        return model;
    }

    @ApiOperation("新增历史诗词")
    @RequestMapping(value = "/addPoem", method = {RequestMethod.PUT})
    public BaseModel addPoem(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                              @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        historyService.addNewHistoryPoem(user_id,source_id,model);
        return model;
    }

    @ApiOperation("分页查询历史诗词")
    @RequestMapping(value = "/getPoem", method = {RequestMethod.GET})
    public BaseModel getPoem(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                              @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        historyService.getHistoryPoem(user_id,pageQueryModel,model);
        return model;
    }



    @ApiOperation("查询用户全部历史记录")
    @RequestMapping(value = "/getAllHistory", method = {RequestMethod.GET})
    public BaseModel getAllHistory(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                   @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        historyService.getHistory(user_id,pageQueryModel,model);
        return model;
    }
}
